<?php

$tags = $model->tags;
?><h2>标签</h2>
<?php
if (count($tags) > 0) {
	$this
		->widget('zii.widgets.grid.CGridView',
			array(
				'id' => 'material-tag-grid',
				'dataProvider' => new CArrayDataProvider($tags,
					array(
						'pagination' => false
					)),
				'enablePagination' => false,
				'template' => "{items}",
				'columns' => array(
					array(
						'name' => 'name',
						'header' => '标签'
					),
					array(
						'class' => 'CButtonColumn',
						'template' => Yii::app()->user->checkAccess('materialManage') ? '{delete}'
							: '',
						'deleteButtonUrl' => 'Yii::app()->controller->createUrl("deleteTag",array("tagId"=>$data->primaryKey,"materialId"=>'
							. $model->id . '))'
					),
				),
			));
} else {
?>
	<div>无</div>
	<?php
	}
	?><?php
  if (Yii::app()->user->checkAccess('materialManage')) {
  ?>
		<div id="material-tag-add" class="form">
		<h2>添加标签</h2>
		<?php
			$tagModel = new MaterialTag();
			$form = $this
				->beginWidget('CActiveForm',
					array(
						'action' => array(
							'material/createTag',
							'materialId' => $model->id,
						),
						'id' => 'material-tag-form',
						'enableAjaxValidation' => false,
					));
		?>
			<div class="row">
				<?php echo $form->labelEx($tagModel, 'name'); ?>
<?php
	$this
		->widget('zii.widgets.jui.CJuiAutoComplete',
			array(
				'model' => $tagModel,
				'attribute' => 'name',
				'sourceUrl' => Yii::app()->controller->createUrl('material/tags'),
				'options' => array(
					'minLength' => '1',
				),
				'htmlOptions' => array(
					'size' => 6,
				),
			));
?>
				<?php echo $form->error($tagModel, 'name'); ?>
			</div>
		
			<div class="row buttons">
				<?php echo CHtml::submitButton('添加'); ?>
			</div>
		<?php $this->endWidget(); ?>
		</div>
		
		<?php
		}

		?>
